<template>
  <uni-nav-bar :title="text" left-icon="left" color="#333" @clickLeft="navBack" statusBar></uni-nav-bar>
  <!-- 车辆详情头部 -->
  <CarTop :carAll="carAll"></CarTop>
  <!-- 菜单 -->
  <MenuBar :list="list"></MenuBar>
</template>

<script setup lang="ts">
import { carDetail } from '@/gql/customer';
import { navBack } from '@/utils/navigator';
import CarTop from '@c/customers/carTop.vue';
import MenuBar from '@c/customers/menuBar.vue';
import { onLoad } from '@dcloudio/uni-app';
import { toPublish } from '@mqtt';
import { ref } from 'vue';

// static
const text = ref(uni.getStorageSync('customersName') + '—车辆');
const list = ref([]);
const carAll = ref({}); //车辆数据
let carID = null as number; //车辆ID

onLoad((options) => {
  list.value = [{ text: '订单', path: `customers/orderList?type=${options.car}` }];
  carID = Number.parseInt(options.id);
  fillSever();
});

function fillSever() {
  const payload = {
    query: carDetail,
    variables: { id: carID },
  };
  toPublish('customers/cart', payload, (obj: any) => {
    const { cart } = obj.data;
    carAll.value = cart;
  });
}
</script>

<style scoped lang="less"></style>
